/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.jr2tecnologia.model;

import br.com.jr2tecnologia.LoggerFactory;
import br.com.jr2tecnologia.model.entity.SmsReceived;
import br.com.jr2tecnologia.model.persistence.DAOException;
import br.com.jr2tecnologia.model.persistence.DAOFactory;
import br.com.jr2tecnologia.model.repository.SmsReceivedRepository;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author ronildo
 */

@Stateless
public class SmsReceivedPersistence implements SmsReceivedPersistenceLocal{

    private static final Logger logger = LoggerFactory.getLogger();

    @PersistenceContext
    private EntityManager em;
    private SmsReceivedRepository smsReceivedRepository;

    @PostConstruct
    public void initialize(){
        smsReceivedRepository = DAOFactory.getSmsReceivedRepository(em);
    }

    public void persist(SmsReceived smsReceived){
        smsReceivedRepository.persist(smsReceived);
    }

    public List<SmsReceived> list(SmsReceived smsReceived){
        try{
            return smsReceivedRepository.list(smsReceived);
        }catch(DAOException e){
            logger.log(Level.SEVERE, "canot list smsReceived", e);
            throw new DAOException(e);
        }
    }

    public List<SmsReceived> listAll(){
        try{
            return smsReceivedRepository.listAll();
        }catch(DAOException e){
            logger.log(Level.SEVERE, "canot list smsReceived", e);
            throw new DAOException(e);
        }
    }
}
